package org.gap.dao;

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.gap.domain.Tiers;

import org.skyway.spring.util.dao.AbstractJpaDao;

import org.springframework.dao.DataAccessException;

import org.springframework.stereotype.Repository;

import org.springframework.transaction.annotation.Transactional;

/**
 * DAO to manage Tiers entities.
 * 
 */
@Repository("TiersDAO")
@Transactional
public class TiersDAOImpl extends AbstractJpaDao<Tiers> implements TiersDAO {

	/**
	 * Set of entity classes managed by this DAO.  Typically a DAO manages a single entity.
	 *
	 */
	private final static Set<Class<?>> dataTypes = new HashSet<Class<?>>(Arrays.asList(new Class<?>[] { Tiers.class }));

	/**
	 * EntityManager injected by Spring for persistence unit 
	 *
	 */
	@PersistenceContext(unitName = "")
	private EntityManager entityManager;

	/**
	 * Instantiates a new TiersDAOImpl
	 *
	 */
	public TiersDAOImpl() {
		super();
	}

	/**
	 * Get the entity manager that manages persistence unit 
	 *
	 */
	public EntityManager getEntityManager() {
		return entityManager;
	}

	/**
	 * Returns the set of entity classes managed by this DAO.
	 *
	 */
	public Set<Class<?>> getTypes() {
		return dataTypes;
	}

	/**
	 * JPQL Query - findTiersByTieFaxContaining
	 *
	 */
	@Transactional
	public Set<Tiers> findTiersByTieFaxContaining(String tieFax) throws DataAccessException {

		return findTiersByTieFaxContaining(tieFax, -1, -1);
	}

	/**
	 * JPQL Query - findTiersByTieFaxContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Tiers> findTiersByTieFaxContaining(String tieFax, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTiersByTieFaxContaining", startResult, maxRows, tieFax);
		return new LinkedHashSet<Tiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findTiersByTieUserCreationContaining
	 *
	 */
	@Transactional
	public Set<Tiers> findTiersByTieUserCreationContaining(String tieUserCreation) throws DataAccessException {

		return findTiersByTieUserCreationContaining(tieUserCreation, -1, -1);
	}

	/**
	 * JPQL Query - findTiersByTieUserCreationContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Tiers> findTiersByTieUserCreationContaining(String tieUserCreation, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTiersByTieUserCreationContaining", startResult, maxRows, tieUserCreation);
		return new LinkedHashSet<Tiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findTiersByTieTelPortableContaining
	 *
	 */
	@Transactional
	public Set<Tiers> findTiersByTieTelPortableContaining(String tieTelPortable) throws DataAccessException {

		return findTiersByTieTelPortableContaining(tieTelPortable, -1, -1);
	}

	/**
	 * JPQL Query - findTiersByTieTelPortableContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Tiers> findTiersByTieTelPortableContaining(String tieTelPortable, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTiersByTieTelPortableContaining", startResult, maxRows, tieTelPortable);
		return new LinkedHashSet<Tiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findTiersByTieDateCreationBefore
	 *
	 */
	@Transactional
	public Set<Tiers> findTiersByTieDateCreationBefore(java.util.Calendar tieDateCreation) throws DataAccessException {

		return findTiersByTieDateCreationBefore(tieDateCreation, -1, -1);
	}

	/**
	 * JPQL Query - findTiersByTieDateCreationBefore
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Tiers> findTiersByTieDateCreationBefore(java.util.Calendar tieDateCreation, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTiersByTieDateCreationBefore", startResult, maxRows, tieDateCreation);
		return new LinkedHashSet<Tiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findTiersByTieTelFix
	 *
	 */
	@Transactional
	public Set<Tiers> findTiersByTieTelFix(String tieTelFix) throws DataAccessException {

		return findTiersByTieTelFix(tieTelFix, -1, -1);
	}

	/**
	 * JPQL Query - findTiersByTieTelFix
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Tiers> findTiersByTieTelFix(String tieTelFix, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTiersByTieTelFix", startResult, maxRows, tieTelFix);
		return new LinkedHashSet<Tiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findTiersByTieTelBureauContaining
	 *
	 */
	@Transactional
	public Set<Tiers> findTiersByTieTelBureauContaining(String tieTelBureau) throws DataAccessException {

		return findTiersByTieTelBureauContaining(tieTelBureau, -1, -1);
	}

	/**
	 * JPQL Query - findTiersByTieTelBureauContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Tiers> findTiersByTieTelBureauContaining(String tieTelBureau, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTiersByTieTelBureauContaining", startResult, maxRows, tieTelBureau);
		return new LinkedHashSet<Tiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findTiersByTieUserCreation
	 *
	 */
	@Transactional
	public Set<Tiers> findTiersByTieUserCreation(String tieUserCreation) throws DataAccessException {

		return findTiersByTieUserCreation(tieUserCreation, -1, -1);
	}

	/**
	 * JPQL Query - findTiersByTieUserCreation
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Tiers> findTiersByTieUserCreation(String tieUserCreation, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTiersByTieUserCreation", startResult, maxRows, tieUserCreation);
		return new LinkedHashSet<Tiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findTiersByTieTypeTiersContaining
	 *
	 */
	@Transactional
	public Set<Tiers> findTiersByTieTypeTiersContaining(String tieTypeTiers) throws DataAccessException {

		return findTiersByTieTypeTiersContaining(tieTypeTiers, -1, -1);
	}

	/**
	 * JPQL Query - findTiersByTieTypeTiersContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Tiers> findTiersByTieTypeTiersContaining(String tieTypeTiers, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTiersByTieTypeTiersContaining", startResult, maxRows, tieTypeTiers);
		return new LinkedHashSet<Tiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findTiersByTieTiers
	 *
	 */
	@Transactional
	public Tiers findTiersByTieTiers(Integer tieTiers) throws DataAccessException {

		return findTiersByTieTiers(tieTiers, -1, -1);
	}

	/**
	 * JPQL Query - findTiersByTieTiers
	 *
	 */

	@Transactional
	public Tiers findTiersByTieTiers(Integer tieTiers, int startResult, int maxRows) throws DataAccessException {
		try {
			return executeQueryByNameSingleResult("findTiersByTieTiers", tieTiers);
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findTiersByTieIdentClientContaining
	 *
	 */
	@Transactional
	public Set<Tiers> findTiersByTieIdentClientContaining(String tieIdentClient) throws DataAccessException {

		return findTiersByTieIdentClientContaining(tieIdentClient, -1, -1);
	}

	/**
	 * JPQL Query - findTiersByTieIdentClientContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Tiers> findTiersByTieIdentClientContaining(String tieIdentClient, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTiersByTieIdentClientContaining", startResult, maxRows, tieIdentClient);
		return new LinkedHashSet<Tiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findAllTierss
	 *
	 */
	@Transactional
	public Set<Tiers> findAllTierss() throws DataAccessException {

		return findAllTierss(-1, -1);
	}

	/**
	 * JPQL Query - findAllTierss
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Tiers> findAllTierss(int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAllTierss", startResult, maxRows);
		return new LinkedHashSet<Tiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findTiersByTieTelFixContaining
	 *
	 */
	@Transactional
	public Set<Tiers> findTiersByTieTelFixContaining(String tieTelFix) throws DataAccessException {

		return findTiersByTieTelFixContaining(tieTelFix, -1, -1);
	}

	/**
	 * JPQL Query - findTiersByTieTelFixContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Tiers> findTiersByTieTelFixContaining(String tieTelFix, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTiersByTieTelFixContaining", startResult, maxRows, tieTelFix);
		return new LinkedHashSet<Tiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findTiersByTieLibExterneContaining
	 *
	 */
	@Transactional
	public Set<Tiers> findTiersByTieLibExterneContaining(String tieLibExterne) throws DataAccessException {

		return findTiersByTieLibExterneContaining(tieLibExterne, -1, -1);
	}

	/**
	 * JPQL Query - findTiersByTieLibExterneContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Tiers> findTiersByTieLibExterneContaining(String tieLibExterne, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTiersByTieLibExterneContaining", startResult, maxRows, tieLibExterne);
		return new LinkedHashSet<Tiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findTiersByTieIdentClient
	 *
	 */
	@Transactional
	public Set<Tiers> findTiersByTieIdentClient(String tieIdentClient) throws DataAccessException {

		return findTiersByTieIdentClient(tieIdentClient, -1, -1);
	}

	/**
	 * JPQL Query - findTiersByTieIdentClient
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Tiers> findTiersByTieIdentClient(String tieIdentClient, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTiersByTieIdentClient", startResult, maxRows, tieIdentClient);
		return new LinkedHashSet<Tiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findTiersByTieEMailContaining
	 *
	 */
	@Transactional
	public Set<Tiers> findTiersByTieEMailContaining(String tieEMail) throws DataAccessException {

		return findTiersByTieEMailContaining(tieEMail, -1, -1);
	}

	/**
	 * JPQL Query - findTiersByTieEMailContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Tiers> findTiersByTieEMailContaining(String tieEMail, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTiersByTieEMailContaining", startResult, maxRows, tieEMail);
		return new LinkedHashSet<Tiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findTiersByTieDateCreationAfter
	 *
	 */
	@Transactional
	public Set<Tiers> findTiersByTieDateCreationAfter(java.util.Calendar tieDateCreation) throws DataAccessException {

		return findTiersByTieDateCreationAfter(tieDateCreation, -1, -1);
	}

	/**
	 * JPQL Query - findTiersByTieDateCreationAfter
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Tiers> findTiersByTieDateCreationAfter(java.util.Calendar tieDateCreation, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTiersByTieDateCreationAfter", startResult, maxRows, tieDateCreation);
		return new LinkedHashSet<Tiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findTiersByTieFax
	 *
	 */
	@Transactional
	public Set<Tiers> findTiersByTieFax(String tieFax) throws DataAccessException {

		return findTiersByTieFax(tieFax, -1, -1);
	}

	/**
	 * JPQL Query - findTiersByTieFax
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Tiers> findTiersByTieFax(String tieFax, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTiersByTieFax", startResult, maxRows, tieFax);
		return new LinkedHashSet<Tiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findTiersByTieLibExterne
	 *
	 */
	@Transactional
	public Set<Tiers> findTiersByTieLibExterne(String tieLibExterne) throws DataAccessException {

		return findTiersByTieLibExterne(tieLibExterne, -1, -1);
	}

	/**
	 * JPQL Query - findTiersByTieLibExterne
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Tiers> findTiersByTieLibExterne(String tieLibExterne, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTiersByTieLibExterne", startResult, maxRows, tieLibExterne);
		return new LinkedHashSet<Tiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findTiersByTieEMail
	 *
	 */
	@Transactional
	public Set<Tiers> findTiersByTieEMail(String tieEMail) throws DataAccessException {

		return findTiersByTieEMail(tieEMail, -1, -1);
	}

	/**
	 * JPQL Query - findTiersByTieEMail
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Tiers> findTiersByTieEMail(String tieEMail, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTiersByTieEMail", startResult, maxRows, tieEMail);
		return new LinkedHashSet<Tiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findTiersByTieNationaliteContaining
	 *
	 */
	@Transactional
	public Set<Tiers> findTiersByTieNationaliteContaining(String tieNationalite) throws DataAccessException {

		return findTiersByTieNationaliteContaining(tieNationalite, -1, -1);
	}

	/**
	 * JPQL Query - findTiersByTieNationaliteContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Tiers> findTiersByTieNationaliteContaining(String tieNationalite, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTiersByTieNationaliteContaining", startResult, maxRows, tieNationalite);
		return new LinkedHashSet<Tiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findTiersByTieNationalite
	 *
	 */
	@Transactional
	public Set<Tiers> findTiersByTieNationalite(String tieNationalite) throws DataAccessException {

		return findTiersByTieNationalite(tieNationalite, -1, -1);
	}

	/**
	 * JPQL Query - findTiersByTieNationalite
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Tiers> findTiersByTieNationalite(String tieNationalite, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTiersByTieNationalite", startResult, maxRows, tieNationalite);
		return new LinkedHashSet<Tiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findTiersByTieTelPortable
	 *
	 */
	@Transactional
	public Set<Tiers> findTiersByTieTelPortable(String tieTelPortable) throws DataAccessException {

		return findTiersByTieTelPortable(tieTelPortable, -1, -1);
	}

	/**
	 * JPQL Query - findTiersByTieTelPortable
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Tiers> findTiersByTieTelPortable(String tieTelPortable, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTiersByTieTelPortable", startResult, maxRows, tieTelPortable);
		return new LinkedHashSet<Tiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findTiersByTieTypeTiers
	 *
	 */
	@Transactional
	public Set<Tiers> findTiersByTieTypeTiers(String tieTypeTiers) throws DataAccessException {

		return findTiersByTieTypeTiers(tieTypeTiers, -1, -1);
	}

	/**
	 * JPQL Query - findTiersByTieTypeTiers
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Tiers> findTiersByTieTypeTiers(String tieTypeTiers, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTiersByTieTypeTiers", startResult, maxRows, tieTypeTiers);
		return new LinkedHashSet<Tiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findTiersByTieDateCreation
	 *
	 */
	@Transactional
	public Set<Tiers> findTiersByTieDateCreation(java.util.Calendar tieDateCreation) throws DataAccessException {

		return findTiersByTieDateCreation(tieDateCreation, -1, -1);
	}

	/**
	 * JPQL Query - findTiersByTieDateCreation
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Tiers> findTiersByTieDateCreation(java.util.Calendar tieDateCreation, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTiersByTieDateCreation", startResult, maxRows, tieDateCreation);
		return new LinkedHashSet<Tiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findTiersByPrimaryKey
	 *
	 */
	@Transactional
	public Tiers findTiersByPrimaryKey(Integer tieTiers) throws DataAccessException {

		return findTiersByPrimaryKey(tieTiers, -1, -1);
	}

	/**
	 * JPQL Query - findTiersByPrimaryKey
	 *
	 */

	@Transactional
	public Tiers findTiersByPrimaryKey(Integer tieTiers, int startResult, int maxRows) throws DataAccessException {
		try {
			return executeQueryByNameSingleResult("findTiersByPrimaryKey", tieTiers);
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findTiersByTieTelBureau
	 *
	 */
	@Transactional
	public Set<Tiers> findTiersByTieTelBureau(String tieTelBureau) throws DataAccessException {

		return findTiersByTieTelBureau(tieTelBureau, -1, -1);
	}

	/**
	 * JPQL Query - findTiersByTieTelBureau
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Tiers> findTiersByTieTelBureau(String tieTelBureau, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTiersByTieTelBureau", startResult, maxRows, tieTelBureau);
		return new LinkedHashSet<Tiers>(query.getResultList());
	}

	/**
	 * Used to determine whether or not to merge the entity or persist the entity when calling Store
	 * @see store
	 * 
	 *
	 */
	public boolean canBeMerged(Tiers entity) {
		return true;
	}
}
